﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PMS.XCMG.Util;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 角色菜单
    /// </summary>
    public partial class Sys_RoleMenu
    {
        public string RoleId { get; set; }
        public string MenuId { get; set; }
    }

    public partial class Sys_RoleMenu
    {
        public Sys_Role Role { get; set; }
        public Sys_Menu Menu { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class Sys_RoleMenuTypeConfig : IEntityTypeConfiguration<Sys_RoleMenu>
    {
        public void Configure(EntityTypeBuilder<Sys_RoleMenu> builder)
        {
            #region 主外键关系
            builder.HasKey(t => new { t.MenuId, t.RoleId });
            builder.HasOne(ur => ur.Role).WithMany().HasForeignKey(k => k.RoleId);
            builder.HasOne(ur => ur.Menu).WithMany().HasForeignKey(k => k.MenuId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.MenuId).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.RoleId).HasMaxLength(EntityDefinition.DefSmallColLen);
            #endregion

            #region 备注
            builder.HasComment("角色菜单");
            #endregion

            #region 种子数据
            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "400" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "401" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "402" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "403" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "404" }
            );

            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "500" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "501" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "502" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "503" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "504" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "506" }
            );

            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "600" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "601" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "602" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "603" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "604" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "605" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "606" }
            );

            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "700" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "701" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "702" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "703" }
            );

            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "800" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "801" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "802" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "803" }
            );

            builder.HasData(
                new Sys_RoleMenu() { RoleId = "1", MenuId = "900" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "901" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "902" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "903" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "904" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "905" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "906" },
                new Sys_RoleMenu() { RoleId = "1", MenuId = "907" }
            );

            #endregion
        }
    }
}
